<?php

/**
 * This is the model class for table "spectacle_rx_dist".
 *
 * The followings are the available columns in table 'spectacle_rx_dist':
 * @property integer $id
 * @property string $od_pd
 * @property string $odsph
 * @property string $od_cyl
 * @property string $od_axis
 * @property string $od_prism
 * @property string $od_add
 * @property string $os_pd
 * @property string $os_sph
 * @property string $os_cyl
 * @property string $os_axis
 * @property string $os_prism
 * @property string $os_add
 * @property integer $rx_id
 * @property integer $personalinfo_id
 *
 * The followings are the available model relations:
 * @property Rx $rx
 * @property PersonalInformation $personalinfo
 */
class SpectacleRxDist extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return SpectacleRxDist the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'spectacle_rx_dist';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('rx_id, personalinfo_id', 'numerical', 'integerOnly'=>true),
			array('od_pd, odsph, od_cyl, od_axis, od_prism, od_add, os_pd, os_sph, os_cyl, os_axis, os_prism, os_add', 'length', 'max'=>5),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, od_pd, odsph, od_cyl, od_axis, od_prism, od_add, os_pd, os_sph, os_cyl, os_axis, os_prism, os_add, rx_id, personalinfo_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'rx' => array(self::BELONGS_TO, 'Rx', 'rx_id'),
			'personalinfo' => array(self::BELONGS_TO, 'PersonalInformation', 'personalinfo_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'od_pd' => 'Od Pd',
			'odsph' => 'Odsph',
			'od_cyl' => 'Od Cyl',
			'od_axis' => 'Od Axis',
			'od_prism' => 'Od Prism',
			'od_add' => 'Od Add',
			'os_pd' => 'Os Pd',
			'os_sph' => 'Os Sph',
			'os_cyl' => 'Os Cyl',
			'os_axis' => 'Os Axis',
			'os_prism' => 'Os Prism',
			'os_add' => 'Os Add',
			'rx_id' => 'Rx',
			'personalinfo_id' => 'Personalinfo',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('od_pd',$this->od_pd,true);
		$criteria->compare('odsph',$this->odsph,true);
		$criteria->compare('od_cyl',$this->od_cyl,true);
		$criteria->compare('od_axis',$this->od_axis,true);
		$criteria->compare('od_prism',$this->od_prism,true);
		$criteria->compare('od_add',$this->od_add,true);
		$criteria->compare('os_pd',$this->os_pd,true);
		$criteria->compare('os_sph',$this->os_sph,true);
		$criteria->compare('os_cyl',$this->os_cyl,true);
		$criteria->compare('os_axis',$this->os_axis,true);
		$criteria->compare('os_prism',$this->os_prism,true);
		$criteria->compare('os_add',$this->os_add,true);
		$criteria->compare('rx_id',$this->rx_id);
		$criteria->compare('personalinfo_id',$this->personalinfo_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public function getFName()
        {       
        return $this->personal_information['FullName']; 
        }
}